package org.millioncall.yueyoga.admin.service.stat;

import java.util.HashMap;
import java.util.Map;

import org.millioncall.openplatform.util.IDGeneratorUtils;

/**
 * html标记
 * 
 * @author zangjinyu
 * @version 1.0.0
 * 
 */
public class HtmlTag {
	private Map<String, String> attributes = new HashMap<String, String>();

	public HtmlTag() {
		this(IDGeneratorUtils.UUID32Id());
	}

	public HtmlTag(String id) {
		setAttribute("id", id);
	}

	public String getId() {
		return getAttribute("id");
	}

	public void setClass(String value) {
		this.attributes.put("class", value);
	}

	public void addClass(String value) {
		String old = this.attributes.get("class");
		if (old == null) {
			old = "";
		}
		old += " " + value;
		this.attributes.put("class", old);
	}

	public void removeClass(String value) {
		String old = this.attributes.get("class");
		if (old != null) {
			old = old.replace(value, "");
		}
		this.attributes.put("class", old);
	}

	public void clearAllClasses() {
		this.attributes.remove("class");
	}

	public String getAttribute(String name) {
		return this.attributes.get(name);
	}

	public void setAttribute(String name, String value) {
		this.attributes.put(name, value);
	}

	public void removeAttribute(String name) {
		this.attributes.remove(name);
	}

	public void clearAllAttributes() {
		this.attributes.clear();
	}

}
